<%@ page language="java"   pageEncoding="UTF-8"%>

<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>


<style type="text/css">

.photo
{
    margin-left:auto;
    margin-right:auto;
    margin-top:20px;
    width:168px;
    height:88px;
    overflow:hidden;
    background-color:#f8fdff;
    border:4px solid #f3f3f3;
    text-align:center;
    vertical-align:bottom;
    line-height:88px; 
    display:block;
}


.photoTitle
{
    margin-left:auto;
    margin-right:auto;
    display:table;
    padding-top:10px;
    
    *padding-left:15px;
    _padding-left:15px;
}
</style>

<link rel="stylesheet" href="<%=path%>/include/styleBase/css/styleBase.css" />
<link rel="stylesheet" href="<%=path%>/include/styleBase/css/ostable.css" />


<script type="text/javascript" src="<%=path%>/include/js/jquery.js"></script>
<script type="text/javascript" src="<%=path%>/include/styleBase/js/style.js"></script>

<script type="text/javascript" src="<%=path%>/include/FileUpload/fileUpload.js"></script>



<script>



function delFile(savePath){
	alert("22"+savePath);
    $.ajax({
		type: "POST", url: "<%=path%>/servlet/FileUploadManagerServlet?method=delFile&filePath="+savePath,
		data:$("#form1").serialize(),
		error:function(){alert("与服务器失去联系，请刷新本页面后再重试！");},
		success: function(msg){}
	});
 }



//删除一行
function deltr(id)
{
	var trs = $("#attrDiv").find("span");
 	$.each(trs,function(i,n){
 			if($(this).attr("id")==id){
 				$(this).remove();
 			}
     });


 	var trs = $("#uploadDiv").find("input");
 	$.each(trs,function(i,n){
 	 	    
 			if($(this).attr("id")==("pathes"+id)){
                var savePath=$(this).attr("value");
 	 			delFile(savePath);
 				$(this).remove();
 			}

 			if($(this).attr("id")==("filenames"+id)){
 				$(this).remove();
 			}
     });
    
}

//增加文件列表 
function addFileList(){
    var excelpath=$("#file1").val(); //文件路径
	var excelname=excelpath.substr(excelpath.lastIndexOf("\\")+1); //文件名
	
    var trSTR=$("#file1").clone(true);
    $("#filelist").append(trSTR); 
    var contentTemplate=$("#contentTemplate").clone(true);
    $("#imageTD1").appentd(contentTemplate); 
    contentTemplate.show(); 
}


$(document).ready(function(){
		
	  $('.upload').fileUploadUI({
        uploadTable: $('.upload_files'),
        downloadTable: $('.download_files'),
        buildUploadRow: function (files, index) {
            var file = files[index];
            var finename = file.name.substring(file.name.lastIndexOf("\\")+1);
            return $(
                '<tr>' +
                '<td width="20px;">' + finename + '<\/td>' +
                '<td width="40px;" class="file_upload_progress"><div><\/div><\/td>' +
                '<td class="file_upload_cancel" style="border:0px;">' +
                '<div style="border-bottom:0px;" class="ui-state-default ui-corner-all ui-state-hover" title="取消">' +
                '<span class="ui-icon ui-icon-cancel" style="border:0px;">取消<\/span>' +
                '<\/div>' +
                '<\/td>' +
                '<\/tr>'
            );
        },
        buildDownloadRow: function (files) {
            //return $('<tr><td>' + file + '<\/td><\/tr>');
            var file = files[0];
            var s= file.id;
            var htmlstr = '<tr id="'+file.id+'" savePath="'+file.savePath+'" fileName="'+file.sourceName+'"><td class="leftspan"></td><td class="text">'+files[0].sourceName+'<a href=\"#2010\" onclick=\"deltr(\''+s+'\')\"> 取消</a>'+'</td></tr>';
            return $(htmlstr);
        }
    });
    
    

    
});


//上传组件参数初始化
var setting={
	id:"FileUpload",
	swfPath:"<%=path%>/include/FileUpload/FileUploadForHr.swf",
	serverPath:"<%=path%>/servlet/FileUploadManagerServlet?method=saveFile",
	imgPath:"<%=path%>/include/FileUpload/upload.jpg",
	width:90,
	height:20,
 	fileSize:"20",
	noFileType:"*.exe",
 	checkAndUploadExtend:checkAndUploadExtend,
 	uploadOnProgressExtend:uploadOnProgressExtend,
 	uploadCompleteExtend:uploadCompleteExtend
};




//上传组件参数初始化
var upPhotoSetting={
	id:"FileUpload",
	swfPath:"<%=path%>/include/FileUpload/FileUploadForHr.swf",
	serverPath:"<%=path%>/servlet/FileUploadManagerServlet?method=saveFile",
	imgPath:"<%=path%>/include/FileUpload/upload.jpg",
	width:90,
	height:20,
 	fileSize:"20",
	noFileType:"*.exe",
 	checkAndUploadExtend:checkAndUploadExtend,
 	uploadOnProgressExtend:uploadOnProgressExtend,
 	uploadCompleteExtend:uploadCompleteExtend
};


		
/*上传文件有效性判断*/
function checkAndUploadExtend(id,serverJson){
	//如果你想获取当前上传组件参数的话
	//var parameters=FU.getSettingById[id];
	if(serverJson.checkType=="all"){
		//各种校验通过,如果你想在文件正式上传前做点什么的话，你就在这做吧！
		//alert("serverJson:"+serverJson);
		
		var htmlstr = '<span class="uploadSpan"><img src="<%=path%>/include/images/file.gif"/>'+serverJson.fileName+'&nbsp;已上传<span id="perspan"></span></span>';
		$("#attrDiv").append(htmlstr);
		
		
		//$("#fileInfo").html(serverJson.fileName);
		//$("#json1").html(FU.jsonToStr(serverJson));
	}else if(serverJson.checkType=="suffix"){
		//文件后缀名有误
		alert("文件后缀名有误1");
	}else if(serverJson.checkType=="noSuffix"){
		//不允许的后缀名出错
		alert("不允许的后缀名有误1");
	}else if(serverJson.checkType=="size"){
		//文件大小有误
		alert("文件大小超过限制,请上传20以内的附件.");
	}
}

/*文件上传进度控制*/
function uploadOnProgressExtend(id,serverJson){
	var percentFormat=Math.floor(serverJson.percent*100);
	//$("#json2").html(FU.jsonToStr(serverJson));
	$("#perspan").html(percentFormat+"%");
}

/*文件上传成功后，将服务器返回值返回到页面*/
function uploadCompleteExtend(id,serverJson){
	//如果你想在文件上传结束后做点什么的话，你就在这做吧！
	//alert(serverJson);
	
	var returnJsonObj= eval("(" + serverJson + ")");
	//alert("222:"+returnJsonObj[0].id);
	
	//将临时文件名span去掉
	removeUploadSpan();
	
    //var htmlstr = '<tr id="'+returnJsonObj[0].id+'" savePath="'+returnJsonObj[0].savePath+'" fileName="'+returnJsonObj[0].sourceName+'"><td class="leftspan"></td><td class="text">'+returnJsonObj[0].sourceName+'<a href=\"#2010\" onclick=\"deltr(\''+returnJsonObj[0].id+'\')\"> 取消</a>'+'</td></tr>';
	
	htmlstr = '&nbsp;&nbsp;&nbsp;<span class="downloadSpan" id="'+returnJsonObj[0].id+'" savePath="'+returnJsonObj[0].savePath+'" fileName="'+returnJsonObj[0].sourceName+'"><img src="<%=path%>/include/images/file.gif"/>'+returnJsonObj[0].sourceName+'&nbsp;&nbsp;<a href=\"#2010\" onclick=\"deltr(\''+returnJsonObj[0].id+'\')\">&nbsp;取消</a>'+'</span>';

	 var htmlstr1="<input name=\"SAVEPATHES\" id=\"pathes"+returnJsonObj[0].id+"\" value=\""+returnJsonObj[0].savePath+"\" style=\"display:block;\" />";
	 
     var htmlstr2="<input name=\"FILENAMES\" id=\"filenames"+returnJsonObj[0].id+"\" value=\""+returnJsonObj[0].sourceName+"\" style=\"display:block;\" />";

	$("#attrDiv").append(htmlstr);

	$("#uploadDiv").append(htmlstr1);
	
    $("#uploadDiv").append(htmlstr2);
}



function removeUploadSpan(){
	var trs = $("#attrDiv").find(".uploadSpan");
 	$.each(trs,function(i,n){
 		$(this).remove();
     });
}




function savenews(){
}



</script>

</head>


<body style="background-color:white;">


<form action="" method="post" name="_form">
       <div id="uploadDiv"></div>
</form>





<div class="stepBar">
   	<table cellpadding="0" cellspacing="0" border="0">
       	<tr>
       		<td class="stepImg"><img src="<%=path%>/include/styleBase/images/da1.jpg"/></td><td>文件上传</td>
       	</tr>
   	</table>
</div>



<div class="feedback" style="">
<table style="width:100%;">
	  <tr>
	      <td class="tdTitle" valign="top" style="">
	          附件：
	      </td>
	      <td style="text-align:left;">
		          <table style="margin:auto;width:100%;">
				       
				  	   <tr>
					       	 <td style="text-align:left;width:30px;">
								<script>
						    		//调用上传组件
									FU.iniFlashPlayer(setting);
								</script>
					         </td>
					         <td>
					         	(请上传文件在小在20M以内的附件)
					         </td>
				      </tr>
				  </table>
				  
	      </td>
	  </tr>
</table>
</div>



<div style="width:100%">
<div id="attrDiv" style="text-align:left;padding-left:55px;">
</div>
</div>


</body>
</html>





